package at.bartinger.snake;

import android.app.Dialog;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.Toast;

public class SettingsDialog extends Dialog{

	private Context context;

	private RadioButton easy;
	private RadioButton normal;
	private int def_vol;
	

	public SettingsDialog(Context context) {
		super(context);
		this.context=context;
		def_vol = 1;
		AudioManager audMgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 
		  def_vol = audMgr.getStreamVolume(AudioManager.STREAM_MUSIC);
		  Log.d("snake",""+10f/15f*def_vol);
	}

	@Override 
	public void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState); 

		setContentView(R.layout.settings); 
		setTitle("Settings"); 

		
		Button buttonOK = (Button) findViewById(R.id.apply); 
		buttonOK.setOnClickListener(new OKListener());
		
		easy = (RadioButton) findViewById(R.id.reasy);
		normal = (RadioButton) findViewById(R.id.rnormal);
		
		
	} 

	private class OKListener implements android.view.View.OnClickListener { 

		@Override 
		public void onClick(View v) {
			if(easy.isChecked()){
				GraphicActivity.delay = 50;
			}else{
				if(normal.isChecked()){
					GraphicActivity.delay = 25;
				}else GraphicActivity.delay = 5;
			}
		
			CheckBox es = (CheckBox) findViewById(R.id.enableSound);
			if(es.isChecked()){
				Log.d("snake","in it");
				FingerSnake.aPlayer.setVolume(10f/15f*def_vol, 10f/15f*def_vol);
			}else{
				FingerSnake.aPlayer.setVolume(0, 0);
			}
			Toast.makeText(context, "Settings saved",Toast.LENGTH_SHORT).show();
			SettingsDialog.this.dismiss(); 
		}

	}
}
